package com.atguigu.gmall.item.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author wk
 * @create 2021-09-02 20:35
 */
@Configuration
public class ThreadPoolConfig {
    @Bean
    public ThreadPoolExecutor ThreadPool(){
        // 自定义线程池
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                15,// 核心线程数
                30,// 最大线程数
                5L, //空闲线程的存活时间
                TimeUnit.SECONDS,// 时间单位
                new LinkedBlockingQueue<>(10),// 工作队列
                Executors.defaultThreadFactory(),// 线程工厂
                new ThreadPoolExecutor.AbortPolicy()// 默认的拒绝策略 抛异常 阻止系统正常运行
        );
        return threadPoolExecutor;
    }
}
